package com.scrumtrek.trainings.tdd.model;

import com.scrumtrek.trainings.tdd.IPaySystem;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Vadim
 * Date: 11.09.13
 * Time: 12:34
 * To change this template use File | Settings | File Templates.
 */
public class Store<T extends Item> implements IStore<T> {
    private IPaySystem paySystem;

    private Set<T> items = new HashSet<T>();

    public Store(IPaySystem paySystem) {
        this.paySystem = paySystem;
    }

    public final Collection<T> getItems() {
        return Collections.unmodifiableCollection(items);
    }

    public final void addItem(T item) {
        items.add(item);
    }

    public final void sellItem(T item) {
        if (removeItem(item)) {
            paySystem.increaseProfit(item.getPrice());
        }
    }

    public final boolean removeItem(T item) {
        return items.remove(item);
    }

    public final int getItemsCount() {
        return items.size();
    }
}
